<% layout('/layouts/default.html', {title: '公司管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-fire"></i> ${text(company.isNewRecord ? '新增公司' : '编辑公司')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${company}" action="${ctx}/sys/company/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('公司编号')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:hidden path="isNewRecord"/>
                                <#form:hidden path="companyCode"/>
<!--                                <#form:input path="viewCode" maxlength="64" readonly="${!company.isNewRecord}" class="form-control required abc"/>-->
                                <#form:input path="viewCode" maxlength="64" readonly="true" class="form-control"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('公司名称')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="companyName" maxlength="200" class="form-control required "/>
                            </div>
                        </div>
                    </div>
				</div>
                <#form:hidden path="fullName" id="fullName" maxlength="200" class="form-control "/>
                <!-- <div class="row" >
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('公司名称')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:hidden path="fullName" maxlength="200" class="form-control "/>
                            </div>
                        </div>
                    </div>
                   <div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('排序号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="treeSort" maxlength="10" class="form-control required digits"/>
							</div>
						</div>
					</div>-->
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('国家/省份/城市')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:treeselect id="area" title="${text('选择')}"
									path="area.areaCode" labelName="area.areaName" labelValue="${company.area.treeNames!}"
									url="${ctx}/sys/area/treeData" returnFullName="true"
									class=" " allowClear="true"/>
							</div>
						</div>
					</div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('传真')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="fax" maxlength="200" class="form-control"/>
                            </div>
                        </div>
                    </div>
					<!--<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('包含部门')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:treeselect id="companyOfficeList" title="${text('部门选择')}"
									value="${@ListUtils.extractToString(officeList!, 'officeCode', ',')}"
									labelValue="${@ListUtils.extractToString(officeList!, 'officeName', ',')}"
									url="${ctx}/sys/office/treeData" checkbox="true"
									class="" allowClear="true"/>
								<#form:hidden name="companyOfficeListJson"/>
							</div>
						</div>
					</div>-->
				</div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title="">
                                <span class="required hide">*</span> ${text('详细地址')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-10">
                                <#form:textarea path="companyAddress" rows="2" maxlength="500" class="form-control "/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4">${text('上级公司')}：</label>
                            <div class="col-sm-8">
                                <#form:treeselect id="parent" title="${text('上级公司')}"
                                path="parent.id" labelPath="parent.companyName"
                                url="${ctx}/sys/company/treeData?excludeCode=${company.id}&ctrlPermi=${@Global.getConfig('user.adminCtrlPermi', '2')}"
                                class="" allowClear="true" canSelectRoot="true" canSelectParent="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4">
                                <span class="required">*</span>${text('默认担保人')}：</label>
                            <div class="col-sm-8">
                                <#form:select path="defaultGuarantor.guarantorId" items="${listGuar}"
                                itemLabel="guarantorName" itemValue="guarantorId" blankOption="true"
                                class="form-control required" />
                            </div>
<!--                            url="${ctx}/sys/company/treeData?excludeCode=${company.id}&ctrlPermi=${@Global.getConfig('user.adminCtrlPermi', '2')}"-->
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('税号')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="taxNumber" maxlength="200" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('联系人信息')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('联系人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="contactPerson" maxlength="200" class="form-control"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('邮箱')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="email" maxlength="200" class="form-control email"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('电话')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="phone" maxlength="200" class="form-control phone"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title="">
                                <span class="required hide">*</span> ${text('联系人地址')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-10">
                                <#form:textarea path="contactPersonAddr" rows="2" maxlength="500" class="form-control "/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-unit">${text('附件信息')}</div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2">附件上传：</label>
                            <div class="col-sm-10">
                                <#form:fileupload id="uploadFile" bizKey="${company.id}" bizType="company_file"
                                uploadType="all" class="" readonly="false" preview="true"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-unit">${text('系统信息')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createDate" readonly="true" maxlength="20" class="form-control"
                                    dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createBy" readonly="true" maxlength="20" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
                                    dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateBy" readonly="true" maxlength="20" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
<!--				<#form:extend collapsed="true" />-->
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('sys:company:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		// var companyOfficeData = $('#companyOfficeListCode').val().split(',');
		// $("#companyOfficeListJson").val(JSON.stringify(companyOfficeData));
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.$('#dataGrid').dataGrid('refreshTreeChildren',
							$('#parentCode').val(), '${company.id}');
				});
			}
		}, "json");
    }
});
$('#companyName').change(function(){
	if ($('#fullName').val()==''){
		$('#fullName').val($(this).val());
	}
});
// 选择上级节点回调方法
function treeselectCallback(id, act, index, layero){
	if (id == 'parent' && (act == 'ok' || act == 'clear')){
		// 创建并初始化下一个节点信息，如：排序号、默认值
		$.get('${ctx}/sys/company/createNextNode?parentCode='
				+$('#parentCode').val(), function(data){
			$('#treeSort').val(data.treeSort);
		});
	}
}
</script>
